<%--
    Document   : view
    Created on : 05/07/2010, 22:40:42
    Author     : junior
--%>
<%@page import="br.com.pegasi.util.Arquivo"%>
<%@page import="se.senai.sgd.negocio.Turmas"%>
<%@page import="se.senai.sgd.entidades.Turma"%>
<%@page import="java.io.*" %>
<%@page import="java.util.*"%>
<%@page import="net.sf.jxls.exception.ParsePropertyException"%>
<%@page import="net.sf.jxls.transformer.XLSTransformer"%>

<%
        String relatorio = request.getParameter("relatorio");
        String templatefile = application.getRealPath("/WEB-INF/modelos/") + "//" + relatorio + ".xls";
        String destinofile = application.getRealPath("/relatorios") + "//" + relatorio + ".xls";

        try {

            Integer id_turma = Integer.valueOf(request.getParameter("id_turma"));
            Map beans = new HashMap();
            Turma turma = Turmas.newInstance().getTurmaById(id_turma,true);
            beans.put("turma", turma);
            XLSTransformer transformer = new XLSTransformer();           
            transformer.transformXLS(templatefile, beans, destinofile);

            File arq = new File(destinofile);
            byte[] b = Arquivo.getByteFile(arq);
            response.setContentType( "application/vnd.ms-excel" );
             response.setHeader("Content-Disposition","attachment; filename =relatorio.xls");
            response.setHeader("Cache-Control", "max-age=30");
            response.setHeader("Pragma", "No-cache");
            response.setDateHeader("Expires", 0);
            response.setContentLength(b.length);


            ServletOutputStream otp = response.getOutputStream();

            otp.write(b, 0, b.length);
            otp.flush();
            otp.close();
        }
        catch (Exception e){
            e.printStackTrace();
        }
%>


